import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import cart from './modules/cart'
import VuexPersistence from 'vuex-persist'
// 创建缓存 告诉插件使用什么缓存来备份

/*
  // 所有数据都缓存
const vuexLocal = new VuexPersistence({
  storage: window.localStorage
}) */
const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
  reducer: state => {
    return {
      cart: state.cart
    }
  }
})

Vue.use(Vuex)
const store = new Vuex.Store({
  modules: {
    user,
    cart
  },
  plugins: [vuexLocal.plugin]
})
export default store
